package com.hs.srm.admin.modules.notice.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hs.srm.admin.modules.notice.entity.NoticeMessageEntity;
import com.hs.srm.admin.modules.notice.service.NoticeMessageService;
import com.hs.srm.admin.modules.notice.service.NoticeMessageTouserService;
import com.hs.srm.common.utils.PageUtils;
import com.hs.srm.common.utils.R;


/**
 * 
 *
 * @author wangpeidong
 * @email wangpdcn@163.com
 * @date 2018-06-28 21:37:31
 */
@RestController
@RequestMapping("notice/noticemessage")
public class NoticeMessageController {
    @Autowired
    private NoticeMessageService noticeMessageService;

    @Autowired
    private NoticeMessageTouserService noticeMessageTouserService;

    /**
     * 列表
     */
    @RequestMapping("/list/{type}")
    //@RequiresPermissions("notice:noticemessage:list")
    public R list(@PathVariable("type") String type){
        List<NoticeMessageEntity> noticeMessageEntities = noticeMessageService.queryByType(type);
        Map<String,Object> map = new HashMap<>(1);
        map.put("list",noticeMessageEntities);
        return R.ok().put("result",map);
    }


    /**
     * 修改消息状态
     * @param type
     * @param id
     * @return
     */
    @RequestMapping("/update/{type}")
    public R updateState(@PathVariable("type")String type,@RequestParam("id") Integer id){
        int status = noticeMessageService.updateStateByType(type,id);
        return R.ok();
    }

    /**
     * 发布公告
     * @return
     */
    @RequestMapping("/publish")
    public R publish(@RequestParam("sendKeeper")int sendKeeper,@RequestParam("sendTeacher")int sendTeacher,@RequestParam("evaluate")String evaluate){
        noticeMessageService.publicMessage(sendKeeper,sendTeacher,evaluate);
        return R.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("notice:noticemessage:info")
    public R info(@PathVariable("id") Long id){
        NoticeMessageEntity noticeMessage = noticeMessageService.selectById(id);

        return R.ok().put("noticeMessage", noticeMessage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("notice:noticemessage:save")
    public R save(@RequestBody NoticeMessageEntity noticeMessage){
        noticeMessageService.insert(noticeMessage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("notice:noticemessage:update")
    public R update(@RequestBody NoticeMessageEntity noticeMessage){
        noticeMessageService.updateAllColumnById(noticeMessage);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("notice:noticemessage:delete")
    public R delete(@RequestBody Long[] ids){
        noticeMessageService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/sendList")
    public R sendList(@RequestParam Map<String, Object> params){
        PageUtils page = noticeMessageTouserService.queryPage(params);
        return R.ok().put("result",page);
    }

}
